//
//  WDLoanDetailHeadView.m
//  Zhihuijinfu
//
//  Created by 王笛 on 2017/1/21.
//  Copyright © 2017年 王笛. All rights reserved.
//

#import "WDLoanDetailHeadView.h"
#import "WDLoan.h"

@interface WDLoanDetailHeadView ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *PhoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *carTypeLabel;
@property (weak, nonatomic) IBOutlet UILabel *carSeriesLabel;
@property (weak, nonatomic) IBOutlet UILabel *carPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *laonMoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *termLabel;
@property (weak, nonatomic) IBOutlet UILabel *productLabel;
@property (weak, nonatomic) IBOutlet UILabel *businessLabel;
@property (weak, nonatomic) IBOutlet UILabel *remarkLabel;
@property (weak, nonatomic) IBOutlet UILabel *lastLabel;


@end

@implementation WDLoanDetailHeadView

+ (instancetype)loanDetailHeadView
{
    WDLoanDetailHeadView *loanDetailHeadView = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
    
    return loanDetailHeadView;
}

- (void)setLoan:(WDLoan *)loan
{
    _loan = loan;
    
    self.nameLabel.text = loan.user_name;
    self.PhoneLabel.text = loan.phone;
    if ([loan.car_type isKindOfClass:[NSNumber class]]) {
        loan.car_type = [NSString stringWithFormat:@"%@", loan.car_type];
    }
    
    if ([loan.brand_id isKindOfClass:[NSNumber class]]) {
        loan.brand_id = [NSString stringWithFormat:@"%@", loan.brand_id];
    }
    
    if ([loan.car_type isEqualToString:@"0"]) {
        self.carTypeLabel.text = @"新车";
    } else {
        self.carTypeLabel.text = @"二手车";
    }
    self.carSeriesLabel.text = [NSString stringWithFormat:@"%@ %@", loan.brand_name,loan.series_name];
    self.carPriceLabel.text = [NSString stringWithFormat:@"%.1f 万", [loan.car_price floatValue]];
    self.laonMoneyLabel.text = [NSString stringWithFormat:@"%.1f 万", [loan.loan_amount floatValue]];
    self.termLabel.text = [NSString stringWithFormat:@"%@ 期", loan.pay_periods];
    self.productLabel.text = loan.product_name;
    self.businessLabel.text = loan.supplier_name;
    if ([loan.reason isEqualToString:@""]) {
        self.remarkLabel.hidden = YES;
    } else {
        self.remarkLabel.text = loan.remark;
    }
    
    [self layoutIfNeeded];
    
    loan.detailHeadH = CGRectGetMaxY(self.lastLabel.frame) + 20;
    
}

@end
